#include<iostream>
#include<vector>
using namespace std;

vector<int> twosum(vector<int>& nums,int target){
    int left = 0;
    int right = nums.size() - 1;
    vector<int> v;

    while(left<right){
        if(nums[left]+nums[right]<target){
            left++;
        }
        else if(nums[left]+nums[right]>target){
            right--;
        }
        else{
            v.push_back(nums[left]);
            v.push_back(nums[right]);
            break;
        }
    }

    return v;
}

int main(){
    int target = 40;
    //cin >> target;
    vector<int> nums = {10, 26, 30, 31, 47, 60};
    vector<int> result = twosum(nums, target);

    for(auto e : result){
        cout << e << " ";
    }
    cout << endl;
    return 0;
}